<template>
	<view class="container">
		<!-- 自定义navbar -->
		<view class="nav-bar">
			<backNav title="我的" bgColor="#E0EEFF" :show-back="false"></backNav>
		</view>

		<view class="user-info-container">
			<!-- <image class="avatar" :src="user.avatar"></image> -->
			<u-avatar class="avatar" src="/static/avatar1.png"></u-avatar>
			<view class="user-name-container">
				<text class="user-name">{{ user.nickName }}</text>
				<text class="school-class">所在学校 | 初二</text>
			</view>
			<view class="user-vip">
				<image src="/static/version_4/Slice24.png"></image>
				<text>V1</text>
			</view>
		</view>

		<view class="vip-container">
			<view class="vip-text">开通/续费/升级VIP</view>
			<view class="vip-btn" @click="toVIP"><text>开通</text></view>
		</view>

		<view class="study-voucher">
			<navigator url="/pages/version_4/study_voucher">
				<view class="voucher-main">
					<view class="voucher-count">
						<image src="/static/version_4/studyTicket.png"></image><text>我的学习券：0</text>
					</view>
					<text>快去获取属于你的学习券吧</text>
				</view>
			</navigator>
			<view class="voucher-btn"><text>获取</text></view>
		</view>

		<view class="menu-container">
			<view class="menu-item" @click="toWatchHistory">
				<view class="menu-item-left">
					<image src="/static/version_4/Slice25.png"></image><text>观看历史</text>
				</view>
				<view class="menu-item-right">
					<!-- <uni-icons color="gray" type="right" size="20"></uni-icons> -->
					<u-icon name="arrow-right" size="30"></u-icon>
				</view>
			</view>
			<view class="menu-item" @click="toMyCourse">
				<view class="menu-item-left">
					<image src="/static/version_4/Slice26.png"></image><text>我的课程</text>
				</view>
				<view class="menu-item-right">
					<!-- <uni-icons color="gray" type="right" size="20"></uni-icons> -->
					<u-icon name="arrow-right" size="30"></u-icon>
				</view>
			</view>
			<!-- <view class="menu-item" @click="toAudit">
				<view class="menu-item-left">
					<image src="/static/version_4/Slice 27@3x.png"></image><text>课程审批</text>
				</view>
				<view class="menu-item-right"><uni-icons color="gray" type="right" size="20"></uni-icons></view>
			</view> -->
			<view class="menu-item" @click="toCollectVideoList">
				<view class="menu-item-left">
					<image src="/static/version_4/Slice28.png"></image><text>我的收藏</text>
				</view>
				<view class="menu-item-right">
					<!-- <uni-icons color="gray" type="right" size="20"></uni-icons> -->
					<u-icon name="arrow-right" size="30"></u-icon>
				</view>
			</view>

			<view class="menu-item" @click="toSetting">
				<view class="menu-item-left">
					<image src="/static/version_4/Slice29.png"></image><text>设置</text>
				</view>

				<view class="menu-item-right">
					<!-- <uni-icons color="gray" type="right" size="20"></uni-icons> -->
					<u-icon name="arrow-right" size="30"></u-icon>
				</view>
			</view>

		</view>


	</view>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import backNav from '@/components/backNav/backNav.vue'

const userInfo = uni.getStorageSync('userInfo')

// 定义响应式数据
const show = ref(false)

// 用户信息
const user = reactive({
	avatar: userInfo.avatar || '/static/images/default_avatar.png',
	nickName: userInfo.nickName || '用户名',
	school: userInfo.schoolName || '所在学校',
	grade: userInfo.gradeName || '初二'
})

// 路由
// const router = useRouter()

// 跳转到VIP页面
const toVIP = () => {
	uni.navigateTo({
		url: '/pages/main/payVip'
	})
}

// 跳转到观看历史
const toWatchHistory = () => {
	uni.navigateTo({
		url: '/pages/history/watchHistory'
	})
}

// 跳转到我的课程
const toMyCourse = () => {
	uni.navigateTo({
		url: '/pages/course/myCourse'
	})
}

// 跳转到我的收藏
const toCollectVideoList = () => {
	uni.navigateTo({
		url: '/pages/favorite/collectVideoList'
	})
}

// 跳转到设置页面
const toSetting = () => {
	uni.navigateTo({
		url: '/pages/main/setting'
	})
}

// 获取学习券
const getStudyVoucher = () => {
	// 这里可以添加获取学习券的逻辑
	console.log('获取学习券')
}

// 页面加载时获取用户信息
onMounted(() => {
	// 模拟获取用户信息
	getUserInfo()
})

// 获取用户信息的函数
const getUserInfo = async () => {
	try {
		// 这里应该调用实际的API获取用户信息
		// const res = await api.getUserInfo()
		// user.avatar = res.avatar
		// user.nickName = res.nickName
		// user.school = res.school
		// user.grade = res.grade
		console.log(111)
		// 示例数据
		// user.avatar = '/static/images/default_avatar.png'
		// user.nickName = '张三'
		// user.school = '第一中学'
		// user.grade = '初二'
	} catch (error) {
		console.error('获取用户信息失败:', error)
	}
}

</script>


<style lang="scss" scoped>
.nav-bar {
	height: 140rpx;
}

.container {
	padding: 30rpx;
	background: linear-gradient(to bottom, #E0EEFF 15%, #ffffff 50%); //渐变色;
}


.user-info-container {
	display: flex;
	flex-direction: row;

	.avatar {
		width: 100rpx;
		height: 100rpx;
		margin-right: 30rpx;
	}

	.user-name-container {
		display: flex;
		flex-direction: column;

		.user-name {
			font-weight: bold;
		}

		.school-class {
			font-size: 13px;
			color: gray;
		}

	}

	.user-vip {
		display: flex;
		flex-direction: row;
		align-items: flex-start;
		margin-left: 20rpx;

		image {
			width: 90rpx;
			height: 50rpx;
		}

		text {
			margin-left: -45rpx;
			margin-top: 7rpx;
			font-size: 24rpx;
			font-weight: bold;
		}
	}
}

.study-voucher {
	z-index: 100000;
	background-color: #fff;
	border-radius: 15rpx;
	margin-top: -270rpx;
	padding: 30rpx;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;

	.voucher-main {
		.voucher-count {
			display: flex;
			align-items: center;
			image {
				width: 50rpx;
				height: 50rpx;
			}

			text {
				margin-left: 10rpx;
				font-weight: bold;
				color: black;
				font-size: 30rpx;
			}
		}

		text {
			font-size: 13px;
			color: gray;
		}
	}

	.voucher-btn {

		width: 120rpx;
		height: 60rpx;
		border-radius: 30rpx;
		background-color: skyblue;
		display: flex;
		justify-content: center;
		align-items: center;


		text {
			color: #fff;
		}
	}
}

.vip-container {
	margin-top: 170rpx;
	height: 120rpx;
	background-color: #FDDBB8;
	width: 100%;
	background-image: url('../../static/images/vip/vipGrade.png');
	background-size: 100% 100%;
	background-position: center;
	background-repeat: no-repeat;
	border-radius: 16rpx;

	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx;
	border-radius: 15rpx;

	.vip-text {
		font-size: 20rpx;
		color: #5e3420;
		margin-left: 300rpx;
	}

	.vip-btn {
		width: 110rpx;
		height: 50rpx;
		background-color: transparent;
		border: solid 1rpx #fff;
		border-radius: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: rgba($color: #fff, $alpha: 0.5);
		//半透明

		text {
			color: #5e3420;
			font-weight: 500;
		}
	}
}

.menu-container {
	border-radius: 15rpx;
	padding: 0 30rpx;
	margin-top: 150rpx;
	display: flex;
	flex-direction: column;
	background-color: #fff;

	.menu-item {
		height: 120rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;

		.menu-item-left {
			display: flex;
			flex-direction: row;
			align-items: center;

			image {
				width: 45rpx;
				height: 45rpx;
			}

			text {
				font-size: 24rpx;
				color: #000;
				margin-left: 14rpx;
			}
		}

		.menu-item-right {}
	}
}
</style>